package org.example.mapper;

import org.apache.ibatis.annotations.*;
import org.example.common.entity.Tenant;

import java.util.List;

public interface TenantMapper {

    // 插入新租户
    @Insert("INSERT INTO tenant (tenant_name, tenant_code, status, created_at, updated_at) " +
            "VALUES (#{tenantName}, #{tenantCode}, #{status}, #{createdAt}, #{updatedAt})")
    void insertTenant(Tenant tenant);

    // 根据ID查询租户
    @Select("SELECT * FROM tenant WHERE tenant_id = #{tenantId} AND deleted_at IS NULL")
    Tenant getTenantById(@Param("tenantId") Long tenantId);

    // 查询所有租户
    @Select("SELECT * FROM tenant WHERE deleted_at IS NULL")
    List<Tenant> getAllTenants();

    // 逻辑删除租户
    @Update("UPDATE tenant SET deleted_at = NOW() WHERE tenant_id = #{tenantId}")
    void deleteTenant(@Param("tenantId") Long tenantId);
}
